<template>
    <div class="table">
        <!-- :height="tabHeader" -->
        <el-table ref="multipleTableRef" style="width: 100%;" :data="props.tableList" stripe :height="tabHeader"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" v-if="props.tableBind.length > 0" width="55" />
            <el-table-column :label="item.label" :width="item.width ? item.width : ''"
                v-for="(item, index) in props.tableBind" :key="index" show-overflow-tooltip>
                <template #default="scope">{{ scope.row[item.property] }}</template>
            </el-table-column>
            <el-table-column label="操作" show-overflow-tooltip>
                <template #default="scope">
                    <slot name="operation" :scope="scope"></slot>
                </template>
            </el-table-column>
            <template #empty>
                <div class="no-data-image">
                    <el-empty :image-size="100" description="暂无数据" />
                </div>
            </template>
        </el-table>

    </div>
</template>

<script setup lang='ts'>
import { ref, onMounted, nextTick, onUnmounted } from 'vue'
//table所需要的参数 { lable:表格头,property:"所绑定的对象" }
//服务端所返回的数据 
const props: any = defineProps({
    tableBind: {
        type: Array,
        default: []
    },
    tableList: {
        type: Array,
        default: []
    }
})
const tabHeader: any = ref(0);
const headerFun = () => {
    nextTick().then(() => {
        const bodyDome = document.getElementsByTagName("body")[0]
        const headerDome = document.getElementsByClassName("header")[0];
        const tagRouterDom = document.getElementsByClassName("tagRouter")[0];
        const paginationDom = document.getElementsByClassName("pagination")[0];
        const searchFormDom = document.getElementsByClassName("searchForm")[0];
        const bulkOperationsDom = document.getElementsByClassName("bulkOperations")[0];
        const bodyHeight = bodyDome.clientHeight
        const headerHeight = headerDome.clientHeight;
        const tagRouterHeight = tagRouterDom.clientHeight;
        const paginationHight = paginationDom.clientHeight;
        const searchFormDomHight = searchFormDom.clientHeight;
        const bulkOperationsDomHight = bulkOperationsDom.clientHeight;
        tabHeader.value = bodyHeight - (headerHeight + tagRouterHeight + paginationHight + searchFormDomHight + bulkOperationsDomHight + 40);// 面包屑上下间距20
        // console.log(tabHeader.value,"表格初始高度通过计算的得知")
    });
}
// 全选 和 单选
const handleSelectionChange = (val: any) => {
    if (val.length > 0) {
        console.log(val[0].date)
    } else {
        console.log("[]")
    }
}
onMounted(() => {

    headerFun()
})

onUnmounted(() => {
});
</script>

<style lang='scss' scoped>
.table {
    border-radius: 5px;
    overflow: hidden;

    ::v-deep(.el-table__header) {
        th {
            background-color: #F5F7FA;
            color: #777;
        }
    }

    ::v-deep(.el-text) {
        padding-right: 10px;
        cursor: pointer;

    }

    .no-data-image {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100px;
        /* 根据需要调整高度 */
    }

}
</style>
